<?php
loadTemp("admin/models/class/classheader.php");
?>
<script type="text/javascript">
$(document).ready(function(){
	loadAdminTopItem();
	activeAdminTopItem("s_c_applyclass");
});
</script>
<?php checkAdminPermission("admin.class.applyclass","admin.class.*");?>
<script type="text/javascript">
$(document).ready(function(){
	bindAjaxForm($("#form_apply_search"),s_applyclass_onSuccess,s_applyclass_onError,"admin_di");
	$("#student_apply_temple").hide();
});
function s_applyclass_onSuccess(data){
	s_applyclass_operatedone(data.code,data.message,data.data);
}
function s_applyclass_onError(data){
	console.log(data);
	s_applyclass_operatedone(-101,"服务器返回了未知的数据，请上报管理员",data.responseText);

}
function s_applyclass_operatedone(id,message,data){
	if(id==-101){
		showMessage("s_applyclass_message",-101,message+"<br><br><pre>"+data+"</pre>");
		return;
	}
	if(id!=0&&id!=3){
		showMessage("s_applyclass_message",id,message);
	}
	if(id==0){
		showMessage("s_applyclass_message",id,message);
	}
	if(data.op=="loadApplyList"){
		$("#form_apply_search").hide();
		$("#s_a_cempty").removeClass("hidden");
		dealList(data.data);
		
	}
	if(data.op=="sent_apply"){
		uid = data.uid;
		$("#s_a_c_apply_"+uid).remove();
	}
}
function dealList(data){
	$.each(data,function(k,v){
		let $tmp = $("#student_apply_temple").clone();	
		$tmp.show();
		$tmp.attr("id","s_a_c_apply_"+k);
		$tmp.find(".s_uid").attr("uid",k);
		$tmp.find(".s_head").attr("src",v.card.head_image_path);
		$tmp.find(".s_name").attr("href",getHomeURL(k)).html(v.card.name);
		$tmp.find(".s_note").html(v.note);
		$("#s_a_cempty").addClass("hidden");
		$("#s_a_c_apply_list").append($tmp);
	});
}
function s_a_c_apply(e){
	uid = e.attr("uid");
	note = e.parent().find(".s_reasion").val();
	if(note==""){note="申请通过";}
	ajaxRequest("uid="+uid+"&note="+note+"&op=approve","admin.php?mod=class&ajax=true&op=deal_apply_student",s_applyclass_onSuccess,s_applyclass_onError);
	
}
function s_a_c_reject(e){
	uid = e.attr("uid");
	note = e.parent().find(".s_reasion").val();
	if(note==""){note="申请失败";}
	ajaxRequest("uid="+uid+"&note="+note+"&op=reject","admin.php?mod=class&ajax=true&op=deal_apply_student",s_applyclass_onSuccess,s_applyclass_onError);
}
function s_a_c_search(classid){
	ajaxRequest("classid="+classid,"admin.php?mod=class&ajax=true&op=search_class_apply",s_applyclass_onSuccess,s_applyclass_onError);
}
</script>
<div class="s_admin_in_container">
	<h2 class="ui dividing header">班级审核</h2>
	<div class="ui message">
		<div class="header">小提示</div>
		<ul class="list">
			<li>这里是班级审核管理模块</li>
			<li>用于批复学生加入班级的申请</li>
		</ul>
	</div>
	<h4 class="ui dividing header">申请列表</h4>
	<div class="ui message hidden" id="s_applyclass_message"></div>
	<form class="ui form" url="admin.php?mod=class&ajax=true&op=search_class_apply" id="form_apply_search">
		<div class="ui action fluid input">
			<div class="ui left icon input">
				<input type="text" name="classid" placeholder="请输入你要审核的班级的班级id">
				<i class="users icon"></i>
			</div>
			<button class="ui button submit" type="submit">确定</button>
		</div>
	</form>
	<div class="ui success message hidden" id="s_a_cempty">该班级没有新的申请</div>
	<div class="ui middle relaxed aligned divided list" id="s_a_c_apply_list"></div>
</div>
<div class="item" id="student_apply_temple">
	<div class="right floated content">
		<a class="lm_item s_uid" onClick="s_a_c_apply($(this));">同意该申请</a>
		<a class="lm_item s_uid" onClick="s_a_c_reject($(this));">拒绝该申请</a>
		<input type="text" class="ui text lm_item s_reasion" name="reasion" placeholder="同意/拒绝理由" value="">
	</div>
	<img class="ui avatar image s_head" src="">
	<div class="content s_description">
		<a class="s_name"></a>
		<div class="lm_item s_note"></div>
	</div>
</div>